package com.hyjx.framework.component.index;

import com.hyjx.framework.service.ConfigManager;
import com.hyjx.framework.uc.menu.MenuModel;
import com.hyjx.framework.uc.menu.MenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.List;

/**
 * 示例，应移至demo包下
 */
@Controller
@RequestMapping("/examples")
public class ExampleController {

    @Resource
    MenuService menuService;

    @RequestMapping(value = "/gotoLogin", method = RequestMethod.GET)
    public ModelAndView gotoLogin(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/login");
        return mav;
    }

    @RequestMapping(value = "/left", method = RequestMethod.GET)
    public ModelAndView left(HttpServletRequest request) {
        MenuModel model = new MenuModel();
        model.setValidity("Y");
        List<MenuModel> list = null;
        try {
            list = menuService.queryMenuModelList(model);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        ModelAndView mav = new ModelAndView("/left");
        mav.addObject("list", list);
        return mav;
    }

    @RequestMapping(value = "/right", method = RequestMethod.GET)
    public ModelAndView right(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/right");
        return mav;
    }

    @RequestMapping(value = "/top", method = RequestMethod.GET)
    public ModelAndView top(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/top");
        return mav;
    }

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public ModelAndView index(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/index");
        String hm = ConfigManager.getConfig("ui.horizontalmenu");
        mav.addObject("hm", hm);
        return mav;
    }

    @RequestMapping(value = "/control", method = RequestMethod.GET)
    public ModelAndView control(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/control");
        return mav;
    }

    @RequestMapping(value = "/nav", method = RequestMethod.GET)
    public ModelAndView nav(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/nav");
        return mav;
    }

    @RequestMapping(value = "/test1", method = RequestMethod.GET)
    public ModelAndView test1(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/test1");
        return mav;
    }

    @RequestMapping(value = "/select", method = RequestMethod.GET)
    public ModelAndView select(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/examples/select");
        return mav;
    }

    @RequestMapping(value = "/tree", method = RequestMethod.GET)
    public ModelAndView tree(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/examples/tree");
        return mav;
    }
}